﻿using System.Security.Principal;

namespace Sidvall.Security
{
	public class CustomPrincipal : IPrincipal
	{
		#region Public Members

		public CustomIdentity Identity { get; set; }

		#region IsInRole

		public bool IsInRole(string role)
		{
			return this.Identity.HasClaim(ClaimTypes.Role, role);
		}

		#endregion

		#region IPrincipal Members

		IIdentity IPrincipal.Identity
		{
			get
			{
				return this.Identity;
			}
		}

		#endregion

		#endregion
		#region Factory Members

		#region NewUnauthenticatedPrincipal

		public static CustomPrincipal NewUnauthenticatedPrincipal()
		{
			CustomIdentity item;

			item = new CustomIdentity()
			{
				IsAuthenticated = false,
			};
			return new CustomPrincipal(item);
		}

		#endregion

		#endregion
		#region Constructors

		public CustomPrincipal(CustomIdentity item)
		{
			this.Identity = item;
		}

		#endregion
	}
}
